package com.unittec.zk.provider.exam.controller;


import com.alibaba.fastjson.JSON;

import com.unittec.zk.provider.exam.service.NoticeInfoService;
import com.unittec.zk.provider.log.Log;
import com.unittec.zk.provider.utils.ValidationUtils;

import com.unittec.zk.sdk.exam.request.*;
import com.unittec.zk.sdk.exam.response.Res201000;
import com.unittec.zk.sdk.log.enums.LogOperateEnum;
import com.unittec.zk.sdk.log.enums.LogStatusEnum;

import com.unittec.zk.sdk.root.domain.GatewayRequest;
import com.unittec.zk.sdk.root.domain.Result;
import com.unittec.zk.sdk.root.enums.BizCode;
import com.unittec.zk.sdk.root.enums.BizCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "公告信息")
public class NoticeController {


    @Resource
    private Log log;

    @Resource
    private NoticeInfoService noticeInfoService;


    /**
     * 公告信息-分页查找
     *
     * @param  req
     * @return Result<Res201000>
     */
    @RequestMapping(value = "/201052", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "公告信息-分页", notes = "公告信息-分页")
    public Result<Res201000> getNoticePaging(@RequestBody GatewayRequest<Req201052> req) {
        log.debug(req, "getNoticePaging {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res201000 res201000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = noticeInfoService.getNoticePage(req.getContent());
            res201000 = new Res201000();
            res201000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("201052", JSON.toJSONString(req), "公告信息-分页", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "getNoticePaging {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("201052", JSON.toJSONString(req), "公告信息-分页", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res201000);
        } else {
            log.addOperateLog("201052", JSON.toJSONString(req), "公告信息-分页", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }


    //公告信息-批量删
    @RequestMapping(value = "/201053", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "公告信息-批量删", notes = "公告信息-批量删")
    public Result<Res201000> delNoticeByIds(@RequestBody GatewayRequest<Req201053> req) {
        log.debug(req, "delNoticeByIds {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res201000 res201000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = noticeInfoService.delNoticeByIds(req.getContent());
            res201000 = new Res201000();
            res201000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("201053", JSON.toJSONString(req), "公告信息-批量删", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "delNoticeByIds {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("201053", JSON.toJSONString(req), "公告信息-批量删", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res201000);
        } else {
            log.addOperateLog("201053", JSON.toJSONString(req), "公告信息-批量删", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }


    //公告信息-批量撤回
    @RequestMapping(value = "/201054", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "公告信息-批量撤回", notes = "公告信息-批量撤回")
    public Result<Res201000> withdrawNoticeByIds(@RequestBody GatewayRequest<Req201054> req) {
        log.debug(req, "withdrawNoticeByIds {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res201000 res201000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = noticeInfoService.withdrawNoticeByIds(req.getContent());
            res201000 = new Res201000();
            res201000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("201054", JSON.toJSONString(req), "公告信息-批量撤回", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "withdrawNoticeByIds {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("201054", JSON.toJSONString(req), "公告信息-批量撤回", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res201000);
        } else {
            log.addOperateLog("201054", JSON.toJSONString(req), "公告信息-批量撤回", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //公告信息-查详情
    @RequestMapping(value = "/201055", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "公告信息-查详情", notes = "公告信息-查详情")
    public Result<Res201000> getNoticeById(@RequestBody GatewayRequest<Req201055> req) {
        log.debug(req, "getNoticeById {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res201000 res201000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = noticeInfoService.getNoticeById(req.getContent());
            res201000 = new Res201000();
            res201000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("201055", JSON.toJSONString(req), "公告信息-查详情", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "getNoticeById {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("201055", JSON.toJSONString(req), "公告信息-查详情", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res201000);
        } else {
            log.addOperateLog("201055", JSON.toJSONString(req), "公告信息-查详情", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }



    //公告信息-增/改
    @RequestMapping(value = "/201056", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "公告信息-增/改", notes = "公告信息-增/改")
    public Result<Res201000> saveOrUpdateNotice(@RequestBody GatewayRequest<Req201056> req) {
        log.debug(req, "saveOrUpdateNotice {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res201000 res201000 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object o = noticeInfoService.saveOrUpdateNotice(req.getContent());
            res201000 = new Res201000();
            res201000.setObject(o);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("201056", JSON.toJSONString(req), "公告信息-增/改", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "saveOrUpdateNotice {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("201056", JSON.toJSONString(req), "公告信息-增/改", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res201000);
        } else {
            log.addOperateLog("201056", JSON.toJSONString(req), "公告信息-增/改", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }


}
